package osb.map.main;

import com.ljp.ani.R;
import osb.map.database.ConfigurationRW;
import osb.map.net.ClientSocket;
import osb.map.publicdata.Public_Operate_And_Data;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;

public class Welcome extends Activity
{

    // 声明线程对象
    public static Thread thread;

    // 网络连接等待的最长时间
    static int timecount = 0; 

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);

        // 服务器
//        thread = new Thread(new ClientSocket()); // 服务器
//        thread.start();
        
        // 检测配置信息
        String str_isautologin = ConfigurationRW.Configuration_R(1, this); // 是否自动登陆
        String str_userid = ConfigurationRW.Configuration_R(2, this);      // 用户ID
        String str_uistype = ConfigurationRW.Configuration_R(3, this);     // 用户风格选择
        String str_username = ConfigurationRW.Configuration_R(4, this);    // 用户名
        String str_uiaccout = ConfigurationRW.Configuration_R(5, this);    // 用户余额
        
        if (str_isautologin != null)
        {
            if (str_isautologin.equals("true"))
                if (str_userid != null) // 自动登录
                {
                    Public_Operate_And_Data.User_id = str_userid; // 用户ID赋值
                    Public_Operate_And_Data.Islogin = true;       // 自动登录

                    if (str_username != null) Public_Operate_And_Data.User_name = str_username;
                    if (str_uiaccout != null) Public_Operate_And_Data.User_accout = Integer.parseInt(str_uiaccout);
                    
                    Public_Operate_And_Data.IsAutoLogin = true;
                }
        }
        if (str_uistype != null)
        {
            int num = Integer.parseInt(str_uistype); // UI风格选择
             Public_Operate_And_Data.UI_Stype_INT_Curren=num;
            
            switch (num)
            {
            case 0:
                Public_Operate_And_Data.UI_Stype_Curren = Public_Operate_And_Data.UI_Stype_green;
                break;
            case 1:
                Public_Operate_And_Data.UI_Stype_Curren = Public_Operate_And_Data.UI_Stype_tuya;
                break;
//            case 2:
//                Public_Operate_And_Data.UI_Stype_Curren = Public_Operate_And_Data.UI_Stype_loli;
//                break;
            case 2:
                Public_Operate_And_Data.UI_Stype_Curren = Public_Operate_And_Data.UI_Stype_chouxiang;
                break;
                default:
                    Public_Operate_And_Data.UI_Stype_Curren = Public_Operate_And_Data.UI_Stype_green;
                	break;
            }
        }

        // 界面跳转
        new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                Intent intent = new Intent();
                intent.setClass(Welcome.this, Main_Activity.class); 
                startActivity(intent);
                Welcome.this.finish();
            }
        }, 3500); // 3秒后进入主界面

    }
    
    // 回退键
    private long exitTime = 0;
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
    	// 双击回退键退出程序
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            if ((System.currentTimeMillis() - exitTime) > 2000)
            {

                exitTime = System.currentTimeMillis();
            }
            else
            {
                finish();
                System.exit(0);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
